<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/sys/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<%@ include file="/WEB-INF/adminui/include/css.jsp" %>
<title>产品管理列表</title>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
	<div class="row">
		<div class="col-sm-2" style="width:18.66666667%">
			<div class="ibox ibox-body">
				<div class="ibox-title">
					<h5>选择企业-园区</h5>
				</div>
				<div class="ibox-content">
					<div id="jstree"></div>
				</div>
			</div>
		</div>
		<div class="col-sm-9">
			<div class="ibox">
				<div class="ibox-body">
					<div class="fixed-table-toolbar">
						<div id="toolbar" class="columns pull-left">
							<c:if test="${pdttype=='1' }">
							<qx:perm code="product_PLANT_ADD">
							<button type="button" class="btn btn-primary" onclick="add()" uilist-hide="ROOT|COMP|PARK">
								<i class="fa fa-plus hidden" aria-hidden="true"></i>添加
							</button>
							</qx:perm>
							<qx:perm code="product_PLANT_DEL">
							<button type="button" class="btn btn-danger" onclick="del()">
								<i class="fa fa-trash hidden" aria-hidden="true"></i>删除
							</button>
							</qx:perm>
							</c:if>
							
							<c:if test="${pdttype=='2' }">
							<qx:perm code="product_YZ_ADD">
							<button type="button" class="btn btn-primary" onclick="add()" uilist-hide="ROOT|COMP|PARK">
								<i class="fa fa-plus hidden" aria-hidden="true"></i>添加
							</button>
							</qx:perm>
							<qx:perm code="product_YZ_DEL">
							<button type="button" class="btn btn-danger" onclick="del()">
								<i class="fa fa-trash hidden" aria-hidden="true"></i>删除
							</button>
							</qx:perm>
							</c:if>
							
							<c:if test="${pdttype=='3' }">
							<qx:perm code="product_JG_ADD">
							<button type="button" class="btn btn-primary" onclick="add()" uilist-hide="ROOT|COMP|PARK">
								<i class="fa fa-plus hidden" aria-hidden="true"></i>添加
							</button>
							</qx:perm>
							<qx:perm code="product_JG_DEL">
							<button type="button" class="btn btn-danger" onclick="del()">
								<i class="fa fa-trash hidden" aria-hidden="true"></i>删除
							</button>
							</qx:perm>
							</c:if>
							
						</div>
						<c:if test="${pdttype=='1' }">
						<div class="columns pull-right" style="margin-left:5px;">
							<button class="btn btn-success" onclick="doexport()">导出Excel</button>
						</div>
						</c:if>
					</div>
					<table id="dataTable" data-mobile-responsive="true">
					</table>
				</div>
			</div>
		</div>
	</div>
</div>
<%@ include file="/WEB-INF/adminui/include/script.jsp" %>
<script type="text/javascript">
var timeBegin = "种植日期";
var timeEnd = "成熟日期";
var pdttypeV = "${pdttype}";
if(pdttypeV=="2"){
	timeBegin = "养殖日期";
	timeEnd = "出栏日期";
}else if(pdttypeV=="3"){
	timeBegin = "加工日期";
	timeEnd = "成品日期";
}
$(function(){
	UiList.render({
		treeUrl: '${path}/parkjstree/menudatacompany.json?module=products&blockType=${pdttype}',
		tableConfig:{
			url: "${path}/products/listdata.json?pdttype=${pdttype}",
			idfield: 'pdtid',
			columns: [
				{checkbox : true},
				{field : 'pdtname', title : '名称'},
				{field : 'amount', title : '产量(公斤)'},
				{field : 'workerName', title : '负责人'},
				{field : 'beginTime', title : timeBegin, formatter : function(value, row, index) {
					return formatDate(value, 'yyyy-MM-dd');
				}},
				{field : 'endTime', title : timeEnd, formatter : function(value, row, index) {
					return formatDate(value, 'yyyy-MM-dd');
				}},
				{field : 'pdtcode', title : '产品编码'},
				{field : 'pbn', title : '二维码'},
				{field : 'pdtid', title : '操作', align : 'center', width:270, formatter : function(value, row, index) {
					var s = '';
					<c:if test="${pdttype=='1' }">
					<qx:perm code="product_PLANT_EDIT">
					s += '<a class="btn btn-primary btn-sm" href="javascript:;" title="修改" onclick="edit(\''+value+'\')">修改</a> ';
					</qx:perm>
					<qx:perm code="product_PLANT_QRCODE">
					s += '<a class="btn btn-danger btn-sm" href="javascript:;" title="绑定二维码" onclick="qrcode(\''+value+'\')">绑定二维码</a> ';
					s += '<a class="btn btn-success btn-sm" href="javascript:;" title="查看二维码" onclick="printQrcode(\''+value+'\')">查看二维码</a>';
					</qx:perm>
					</c:if>
					
					<c:if test="${pdttype=='2' }">
					<qx:perm code="product_YZ_EDIT">
					s += '<a class="btn btn-primary btn-sm" href="javascript:;" title="修改" onclick="edit(\''+value+'\')">修改</a> ';
					</qx:perm>
					<qx:perm code="product_YZ_PLANT_QRCODE">
					s += '<a class="btn btn-danger btn-sm" href="javascript:;" title="绑定二维码" onclick="qrcode(\''+value+'\')">绑定二维码</a> ';
					s += '<a class="btn btn-success btn-sm" href="javascript:;" title="查看二维码" onclick="printQrcode(\''+value+'\')">查看二维码</a>';
					</qx:perm>
					</c:if>
					
					<c:if test="${pdttype=='3' }">
					<qx:perm code="product_JG_EDIT">
					s += '<a class="btn btn-primary btn-sm" href="javascript:;" title="修改" onclick="edit(\''+value+'\')">修改</a> ';
					</qx:perm>
					<qx:perm code="product_JG_PLANT_QRCODE">
					s += '<a class="btn btn-danger btn-sm" href="javascript:;" title="绑定二维码" onclick="qrcode(\''+value+'\')">绑定二维码</a> ';
					s += '<a class="btn btn-success btn-sm" href="javascript:;" title="查看二维码" onclick="printQrcode(\''+value+'\')">查看二维码</a>';
					</qx:perm>
					</c:if>
					
					return s;
				}}
			]
		}
	});
	
});

function add(){
	UiList.open('${path}/products/add.do?pdttype=${pdttype}', '添加产品信息');
}
function qrcode(id){
	UiList.selectPage('${path}/products/bindQrcode.do?pdtid='+id, '选择二维码', function(page){
		var data = page.getSelectedData();
		if(data){
			$.ajax({
				type : 'POST',
				data : {pdtid:id, qrnumid: data.qrnumid},
				url : '${path}/products/addBindQrcode.json',
				success : function(data) {
					if(!UiUtil.hasErrors(data)){
						layer.msg("绑定二维码成功", {icon: 1});
					}
				}
			});
		}
	});
}
function del(){
	UiList.dialog('${path}/products/delete.json', '您确定要删除选中的产品信息吗？', '删除产品信息成功.');
}
function edit(id){
	UiList.open('${path}/products/edit.do?pdtid='+id, '修改产品信息');
}

function printQrcode(id){
	UiList.open('${path}/products/qrcode.do?pdtid='+id, '查看二维码');
}

function doexport(){
	var node = UiList.getSelectedTreeNode();
	var url = "${path}/products/doexport.do?pdttype=${pdttype}&datatype="+node.type+"&leftdata="+node.id;
	window.open(url, '_blank');
}

</script>
</body>
</html>